package com.me.chat.service.impl.relation;

import com.me.chat.mapper.relation.SingleRelationMapper;
import com.me.chat.pojo.relation.SingleRelation;
import com.me.chat.pojo.relation.qo.SingleRelationQO;
import com.me.chat.service.relation.SingleRelationService;
import com.me.chat.util.SimpleUserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Authhor: qiu
 * @Date: 2021/12/18 2:24 下午
 */

@Service
public class SingleRelationServiceImpl implements SingleRelationService {

    @Autowired
    SingleRelationMapper singleRelationMapper;

    @Override
    public List<SingleRelation> selSingleRelation(SingleRelationQO singleRelationQO) {
        String userId = SimpleUserInfo.getUserId();
        //设置当前登录者的用户id
        singleRelationQO.setOwnerId(userId);
        List<SingleRelation> singleRelations = singleRelationMapper.selSingleRelation(singleRelationQO);
        return singleRelations;
    }

    @Override
    public void addSingleRelation(String user1,String user2) {
        SingleRelationQO singleRelationQO = new SingleRelationQO();
        singleRelationQO.setOwnerId(user1);
        singleRelationQO.setTargetId(user2);
        singleRelationQO.setCreatedTime(LocalDateTime.now());
        singleRelationMapper.addSingleRelation(singleRelationQO);
    }
}
